import request from "@/utils/request";
const baseUrlV2 = '/api'
const defaultApi = (apiName) => {
    return {
        tree: (params) => request.get(`/${apiName}/tree`, { params }),
        list: (params) => request.get(`/${apiName}/list`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    menu: {
        ...defaultApi('system/menu'),
        page: undefined,
        list: (params) => request.get(`/system/menu/tree`, { params }),
    },
    role: {
        ...defaultApi('system/role'),
        roleList: () => request.get('/system/role/simple-list'),
        getRoleMenus: (roleId) => request.get('/system/permission/list-role-menus?roleId=' + roleId),
        updateRoleMenus: (data) => request.post('/system/permission/assign-role-menu', data)
    },
    systemUser: {
        ...defaultApi('system/user'),
        getUserRoles: (userId) => request.get('/system/permission/list-user-roles?userId=' + userId),
        updateUserRoles: (data) => request.post('/system/permission/assign-user-role', data)
    },
    login: (data) => request.post('/system/auth/login', data),
    getUserInfo: () => request.get('/system/auth/get-permission-info'),
    file: defaultApi('file'),
    banner: {
        ...defaultApi('banner')
    },
    product: {
        ...defaultApi('product')
    },
    productSpec: {
        ...defaultApi('productSpec')
    },
    productSku: {
        ...defaultApi('productSku'),
        generate: (data) => request.post('/productSku/generate', data),
        check: (data) => request.post('/productSku/check', data),
        batch: (data) => request.post('/productSku/batch', data)
    },
    category: {
        ...defaultApi('productCategory')
    },
    travel:  {
        ...defaultApi('travel')
    },
    travelCategory:{
        ...defaultApi('travelCategory')
    },
    travelSpec: {
        ...defaultApi('travelSpec')
    },
    travelSku: {
        ...defaultApi('travelSku'),
        generate: (data) => request.post('/travelSku/generate', data),
        check: (data) => request.post('/travelSku/check', data),
        batch: (data) => request.post('/travelSku/batch', data)
    },
    travelSkuStock: {
        ...defaultApi('travelSkuStock'),
        batchDelete: (data) => request.post('/travelSkuStock/batchDelete', data)
    },
    interview: {
        ...defaultApi('interview')
    },
    article: {
        ...defaultApi('article')
    },
    articleCategory: {
        ...defaultApi('article-category')
    },
    qa: {
        ...defaultApi('qa')
    },
    order: {
        ...defaultApi('order'),
        confirm: (data) => request.post('/order/confirm', data),
        cancel: (data) => request.post('/order/cancel', data),
        complete: (data) => request.post('/order/complete', data),
        createOrderRefund: (data) => request.post('/order/refund', data),
        confirmOrderRefund: (data) => request.post('/order/refund/confirm', data),
    },
    orderItem: {
        ...defaultApi('orderItem')
    },
    travelOrder: {
        ...defaultApi('travelOrder'),
        confirm: (data) => request.post('/travelOrder/confirm', data),
        refund: (data) => request.post('/travelOrder/refund', data),
        refundConfirm: (data) => request.post('/travelOrder/refund/confirm', data),
        complete: (data) => request.post('/travelOrder/complete', data),
        groupList: () => request.get('/travelOrder/groupList'),
    },
    travelOrderItem: {
        ...defaultApi('travelOrderItem')
    },
    travelShareOrder: {
        ...defaultApi('travelShareOrder'),
        detail: (id) => request.get(`/travelShareOrder/${id}`),
    },
    travelCustom: {
        ...defaultApi('travelCustom')
    },
    orderLog: {
        ...defaultApi('orderLog')
    },
    questionBank: {
        ...defaultApi('question-bank')
    },
    question: {
        ...defaultApi('question')
    },
    questionOption: {
        ...defaultApi('question-option')
    },
    notice: {
        ...defaultApi('notice')
    },
    store: {
        ...defaultApi('store'),
        audit: (data) => request.post('/store/audit', data),
    },
    config: {
        ...defaultApi('config')
    },
    user: {
        ...defaultApi('user')
    },
    recharge: {
        ...defaultApi('recharge'),
        refund: (data) => request.post('/recharge/refund', data),
        refundConfirm: (data) => request.post('/recharge/refund/confirm', data)
    },
    userPost: {
        ...defaultApi('userPost')
    }
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
